<%--
  Created by IntelliJ IDEA.
  User: asus
  Date: 2020/5/26
  Time: 16:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="true" %>
<html>
<head>
    <title>仓库</title>
    <%@include file="/comm/head.jsp"%>
</head>
<body>
<div id="root">

    <modal v-model="addFlag" title="添加仓库" @on-ok="add">

        <i-form :label-width="80" style="padding: 30px" >
            <form-item label="管理者:">
                <i-select v-model="store.userId" style="width: 110px">
                    <i-Option v-for="item in providerList" :value="item.id" :key="item.id">{{item.userCode}}</i-Option>
                </i-select>
            </form-item>
            <form-item label="名称:">
                <i-input v-model="store.sname"size="large"/>
            </form-item>
        </i-form>
    </modal>


    <card style="margin-top:50px">
        <i-button type="success" @click="toAdd">添加仓库</i-button>
    </card>

    <i-table :columns="columns" :data="pageResult.rows"  :height="300"  border stripe>
        <template slot-scope="{row}" slot="userCode">
            <span>{{row.user.userCode}}</span>
        </template>
        <template slot-scope="{row,index}"  slot="action">
            <i-button type="warning" size="small">修 改</i-button>
            <i-button type="error"  size="small">删 除</i-button>
        </template>

    </i-table>

    <Page :total="pageResult.total"
          :page-size="pageSize"
          @on-change="pageNo=arguments[0];search();"
          show-sizer
          :page-size-opts="[5,10,15]"
          @on-page-size-change="pageSize=arguments[0];search();"
    />


</div>
<script>
    new Vue({
        el:"#root",
        data:{
            columns:[
                {type:"selection",width:60,align:"center"},//自动开启多选功能
                { key:"id",title:"编号"},
                {key:"sname",title:"名称"},
                {slot:"userCode",title:"管理者"},
                {title:"操作",slot:"action",width:300}
            ],
            pageResult:{
                rows:[],
                total:50
            },
            pageNo:1,
            pageSize:5,
            storeVo:{},
            store:{},
            providerList:[],
          addFlag:false,
          updateFlag:false


        },
        methods:{
            search(){
                axios.get(`${ctx}/sys/cangKu/search/${this.pageNo}/${this.pageSize}`,{params:this.store})
                    .then(({data})=>{
                        this.pageResult=data.result;
                    });
            },
            searchProvider(){
                axios.get(`${ctx}/sys/user/lists`)
                    .then(({data})=>{
                        this.providerList=data.result;
                    });
            },

            toAdd(){
                this.store = {};
                this.addFlag=true;

            },
            add(){
                console.log(this.store);
                axios.post(`${ctx}/sys/cangKu/add`,this.store)
                    .then(({data})=>{
                        this.addFlag=false;//关闭模态框
                        iview.Message.success({content:data.msg});
                        this.search();

                    });
            },
        },
        mounted(){
            this.search();
            this.searchProvider();
        }
        });
</script>
</body>
</html>
